package com.ingenieria;

import java.util.ArrayList;
import java.util.HashMap;

import android.app.Activity;
import android.content.Context;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

public class ResultadosAdapter extends BaseAdapter {
	private static LayoutInflater inflater = null;
	private Activity activity;
	private String[][] datalocal;
	public App_ImageLoader imageLoader;
	ArrayList<HashMap<String, String>> map = new ArrayList<HashMap<String, String>>();

	
	public ResultadosAdapter(Activity a,  ArrayList<HashMap<String, String>> menuItems){
			map = menuItems;
			inflater = (LayoutInflater) a.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
             imageLoader = new App_ImageLoader(a.getApplicationContext());
	}
	
	@Override
	public int getCount() {
		Log.i("Size", ""+map.size());
		return map.size();
	}
	
	@Override
	public Object getItem(int position) {
		return position;
	}

	@Override
	public long getItemId(int position) {
		return position;
	}
	
    public static class ViewHolder {
        public TextView titile;
        public TextView date;
        public TextView description;
        public ImageView imagen;
}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		ViewHolder holder;
			if(convertView == null){
				convertView = inflater.inflate(R.layout.resultadositems, null);
				holder = new ViewHolder();
				holder.titile = (TextView) convertView.findViewById(R.id.title);
				holder.date = (TextView) convertView.findViewById(R.id.date);
				holder.description = (TextView) convertView.findViewById(R.id.descriptionSmall);
				holder.imagen = (ImageView) convertView.findViewById(R.id.imagen);
				convertView.setTag(holder);
			}else{
//				Log.i("GETVIEW", ""+datalocal[position][1]);
				holder = (ViewHolder) convertView.getTag();
				holder.titile.setText(map.get(position).get("titulo"));
				holder.date.setText(map.get(position).get("fecha"));
				holder.description.setText(map.get(position).get("desc_corta"));
				imageLoader.DisplayImage(map.get(position).get("url_imagen"), activity, holder.imagen);
			}
		return convertView;
	}
}
